// Echo1 prints its command-line arguments.
package main

import (
	"fmt"
	"sync"
	"time"
)

//输出程序输入的参数

var cha chan int

var wait sync.WaitGroup

func main() {
	//var s, sep string
	//for i := 1; i < len(os.Args); i++ {
	//	s += sep + os.Args[i]
	//	sep = " "
	//}
	//fmt.Println(s)
	//将数据放入管道
	cha = make(chan int, 30)
	for i := 1; i <= 30; i++ {
		cha <- i
	}
	time.Sleep(time.Second * 2)
	defer close(cha)
	wait.Add(2)
	go JiShu(cha)
	go OShu(cha)
	wait.Wait()
	fmt.Println("结束")

}

func OShu(ch chan int) {
	//var temp int
	for true {
		select {
		case temp := <-ch:
			if temp%2 == 0 {
				fmt.Println("输出偶数", temp)
			} else {
				ch <- temp
			}
		default:
			wait.Done()
			return
		}
	}
}

func JiShu(ch chan int) {
	//var temp int
	for true {
		select {
		case temp := <-ch:
			if temp%2 != 0 {
				fmt.Println("输出奇数", temp)
			} else {
				ch <- temp
			}
		default:
			wait.Done()
			return
		}
	}
}
